package com.ss.android.article.base.feature.detail.model;

import com.ss.android.b.a.BaseAdsData;
import com.ss.android.image.model.ImageInfo;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * 1: banner
 * 2: image
 * 3: mixed
 * 4: media
 * 5: phone
 * 6: image_titlebar
 * 7: image_recom
 * 8:
 */
public class g extends BaseAdsData {
    public String label;
    public String title;
    public List imageList;
    private int type;

    public g(int type) {
        this.type = type;
    }

    public void initWithJO(JSONObject jo) {
        if (jo != null) {
            super.initWithJO(jo);
            this.label = jo.optString("label");
            this.title = jo.optString("title");
            JSONArray imageListJA = jo.optJSONArray("image_list");
            this.imageList = null;
            ArrayList list = ImageInfo.optImageList(imageListJA, false);
            if (list != null && !((List) list).isEmpty()) {
                this.imageList = list;
            }
        }
    }

    public boolean isValid() {
        return (this.type == 0
                || this.type == 1
                || this.type == 2
                || this.type == 3
                || this.type == 4
                || this.type == 5
                || this.type == 6
                || this.type == 7) && super.isValid();
    }

    public final boolean isGroupImage() {
        if (this.imageList != null
                && this.imageList.size() >= 3) {
            int count = 0;
            while (true) {
                if (count >= 3) {
                    break;
                } else if (this.imageList.get(count) != null) {
                    ++count;
                    continue;
                }
                return false;
            }
            return true;
        } else {
            return false;
        }
    }
}

